$(function () {

    var attendancesheet_datagrid = $('#attendancesheet_datagrid');

    //数据表格
    attendancesheet_datagrid.datagrid({
        url: "/attendancesheet/list.do",
        striped: true,
        singleSelect: true,
        pagination: true,
        rownumbers: true,
        toolbar: "#tb",
        columns:[[
            {field:'id',title:'考勤编码',width:100},
            {field:'name',title:'名字',width:100},
            {field:'signintime',title:'签到时间',width:100,align:'right'},
            {field:'signbacktime',title:'签退时间',width:100},
            {field:'signinstate',title:'签到状态',width:100,formatter:function (value,row,index) {
                    //状态格式化
                    if(value){
                        return "<span style='color: green;'>已签到</span>"
                    }else{
                        return "<span style='color: red;'>未签到</span>"
                    }
                }},
            {field:'signoutstate',title:'签退状态',width:100,formatter:function (value,row,index) {
                    //状态格式化
                    if(value){
                        return "<span style='color: green;'>已签退</span>"
                    }else{
                        return "<span style='color: red;'>未签退</span>"
                    }
                }},
        ]]
    })


    var cmdObj = {
        //刷新
        reload: function () {
            attendancesheet_datagrid.datagrid("reload");
        },
        //导出文件
        exportExcel: function () {
            var columnField = attendancesheet_datagrid.datagrid('getColumnFields');
            console.log(columnField);
            var table = [];
            for (var i = 0; i < columnField.length; i++) {
                var tableName = attendancesheet_datagrid.datagrid('getColumnOption', columnField[i]).title;
                table.push(encodeURIComponent(encodeURIComponent(tableName)));
            }
            window.location.href = "/attendancesheet/exportExcel.do?titles=" + table
        },
        //高级查询
        searchT: function () {
            //获取到id为keyword的值
            var kw = $("#keyword").val();
            //然后调用load方法,带keyword参数过去
            $('#attendancesheet_datagrid').datagrid('load',{
                keyword: kw
            });
        }
        //end
    }
//给按钮绑定事件
    $("a[data-cmd]").click(function () {
        var cmd = $(this).data("cmd");

        cmdObj[cmd]();
    })
//end


})
